package com.fr.privilege.authority;

import com.fr.base.StringUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.privilege.allocation.Allocation;
import com.fr.privilege.allocation.FileFrag;
import com.fr.privilege.authentication.Authentication;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class AuthorityControl extends Control
{
  public boolean access(Authentication paramAuthentication, String paramString, int paramInt)
  {
    Authority[] arrayOfAuthority = paramAuthentication.getAuthorities();
    if ((arrayOfAuthority == null) || (arrayOfAuthority.length == 0))
      return false;
    paramString = StringUtils.perfectStart(paramString, "/");
    for (int i = 0; i < arrayOfAuthority.length; ++i)
    {
      Allocation localAllocation;
      int j;
      FileFrag localFileFrag;
      Authority localAuthority = arrayOfAuthority[i];
      AuthorityAllocation localAuthorityAllocation = getAuthorityAllocation(localAuthority.getName());
      if (localAuthorityAllocation != null)
      {
        if (localAuthorityAllocation.getAllocation() == null)
          break label280:
        localAllocation = localAuthorityAllocation.getAllocation();
        switch (paramInt)
        {
        case 0:
          j = 0;
          while (true)
          {
            if (j >= localAllocation.getViewCount())
              break label280;
            localFileFrag = localAllocation.getView(j);
            if (paramString.startsWith(localFileFrag.getPath()))
              return true;
            ++j;
          }
        case 1:
          j = 0;
          while (true)
          {
            if (j >= localAllocation.getFormCount())
              break label280;
            localFileFrag = localAllocation.getForm(j);
            if (paramString.startsWith(localFileFrag.getPath()))
              return true;
            ++j;
          }
        case 2:
          j = 0;
          while (true)
          {
            if (j >= localAllocation.getWriteCount())
              break label280;
            localFileFrag = localAllocation.getWrite(j);
            if (paramString.startsWith(localFileFrag.getPath()))
              return true;
            ++j;
          }
        case 3:
          for (j = 0; j < localAllocation.getDesignCount(); ++j)
          {
            localFileFrag = localAllocation.getDesign(j);
            if (paramString.startsWith(localFileFrag.getPath()))
              return true;
          }
        }
      }
    }
    label280: return false;
  }

  public String getID()
  {
    return "1";
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
      this.authorityAllocationMap.clear();
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("AuthorityAllocation".equals(str))
      {
        AuthorityAllocation localAuthorityAllocation = new AuthorityAllocation();
        paramXMLableReader.readXMLObject(localAuthorityAllocation);
        addAuthorityAllocation(localAuthorityAllocation);
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    Iterator localIterator = authorityAllocationIterator();
    while (true)
    {
      AuthorityAllocation localAuthorityAllocation;
      do
      {
        if (!(localIterator.hasNext()))
          return;
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        localAuthorityAllocation = (AuthorityAllocation)localEntry.getValue();
      }
      while (localAuthorityAllocation == null);
      localAuthorityAllocation.writeXML(paramXMLPrintWriter);
    }
  }
}